package com.ruoyi.project.good.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.good.domain.GoodsAssemble;
import com.ruoyi.project.good.service.IGoodsAssembleService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 商品拼团配置Controller
 * 
 * @author ruoyi
 * @date 2020-07-01
 */
@RestController
@RequestMapping("/good/assemble")
public class GoodsAssembleController extends BaseController
{
    @Autowired
    private IGoodsAssembleService goodsAssembleService;

    /**
     * 查询商品拼团配置列表
     */
    @PreAuthorize("@ss.hasPermi('good:assemble:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsAssemble goodsAssemble)
    {
        startPage();
        List<GoodsAssemble> list = goodsAssembleService.selectGoodsAssembleList(goodsAssemble);
        return getDataTable(list);
    }

    /**
     * 导出商品拼团配置列表
     */
    @PreAuthorize("@ss.hasPermi('good:assemble:export')")
    @Log(title = "商品拼团配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GoodsAssemble goodsAssemble)
    {
        List<GoodsAssemble> list = goodsAssembleService.selectGoodsAssembleList(goodsAssemble);
        ExcelUtil<GoodsAssemble> util = new ExcelUtil<GoodsAssemble>(GoodsAssemble.class);
        return util.exportExcel(list, "assemble");
    }

    /**
     * 获取商品拼团配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('good:assemble:query')")
    @GetMapping(value = "/{assembleId}")
    public AjaxResult getInfo(@PathVariable("assembleId") Long assembleId)
    {
        return AjaxResult.success(goodsAssembleService.selectGoodsAssembleById(assembleId));
    }

    /**
     * 新增商品拼团配置
     */
    @PreAuthorize("@ss.hasPermi('good:assemble:add')")
    @Log(title = "商品拼团配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsAssemble goodsAssemble)
    {
        return toAjax(goodsAssembleService.insertGoodsAssemble(goodsAssemble));
    }

    /**
     * 修改商品拼团配置
     */
    @PreAuthorize("@ss.hasPermi('good:assemble:edit')")
    @Log(title = "商品拼团配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsAssemble goodsAssemble)
    {
        return toAjax(goodsAssembleService.updateGoodsAssemble(goodsAssemble));
    }

    /**
     * 删除商品拼团配置
     */
    @PreAuthorize("@ss.hasPermi('good:assemble:remove')")
    @Log(title = "商品拼团配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{assembleIds}")
    public AjaxResult remove(@PathVariable Long[] assembleIds)
    {
        return toAjax(goodsAssembleService.deleteGoodsAssembleByIds(assembleIds));
    }
}
